package com.example.controller;

import com.example.pojo.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("user")
public class UserController 
{
	@Autowired
	UserService userService;
	
	@GetMapping("/spend")
	public void spend(@RequestParam("id") Integer id,@RequestParam("exp") Integer exp)
	{
		User one = userService.getById(id);
		Integer money = one.getMoney();
		if (money < exp)
		{
			throw new RuntimeException("账户金额不足");
		}
		money-=exp;
		one.setMoney(money);
		userService.updateById(one);
	}
}
